# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           compiler_blacklist_versions 1.0
PortGroup           conflicts_build 1.0
PortGroup           gobject_introspection 1.0
PortGroup           cmake 1.1
PortGroup           legacysupport 1.0

name                poppler
conflicts           xpdf-tools
version             0.89.0
license             GPL-2+
maintainers         {devans @dbevans} openmaintainer
categories          graphics
platforms           darwin
homepage            https://poppler.freedesktop.org/

description         Poppler is a PDF rendering library based on the xpdf-3.0 code base.
long_description    ${description}

master_sites        ${homepage} \
                    gentoo

use_xz              yes

checksums           rmd160  ed31e81e3a316795a4e3dd6c5dea45d82752528d \
                    sha256  fba230364537782cc5d43b08d693ef69c36586286349683c7b127156a8ef9b5c \
                    size    1612156

depends_build-append \
                    port:pkgconfig

depends_lib-append  port:bzip2 \
                    port:curl \
                    port:expat \
                    port:fontconfig \
                    port:freetype \
                    port:jpeg \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    port:lcms2 \
                    port:libiconv \
                    port:libpng \
                    port:nss \
                    port:openjpeg \
                    port:poppler-data \
                    port:tiff \
                    port:zlib

# remove top-level paths, such that internal headers and
# libraries are used instead of any already-installed ones.
configure.ldflags-delete -L${prefix}/lib
configure.cppflags-delete -I${prefix}/include

configure.ldflags-append -liconv
gobject_introspection yes

# C++14, thread_local
compiler.cxx_standard 2014
configure.cxxflags-append -std=c++14
compiler.blacklist-append {clang < 800.0.38}

# https://bugs.freedesktop.org/show_bug.cgi?id=106417
patchfiles-append   patch-bug106417.diff

# https://trac.macports.org/ticket/57167
patchfiles-append   patch-trac-57167.diff

configure.args-append \
                    -DENABLE_UNSTABLE_API_ABI_HEADERS=ON \
                    -DENABLE_QT5=OFF \
                    -DBUILD_GTK_TESTS=OFF \
                    -DBUILD_QT5_TESTS=OFF \
                    -DBUILD_CPP_TESTS=OFF \
                    -DWITH_NSS3=ON

subport poppler-qt5 {
    PortGroup qt5 1.0

    patchfiles-append       patch-qt5-106118.diff

    configure.env-append    MOCQT5=${qt_bins_dir}/moc
    configure.args-delete   -DENABLE_QT5=OFF
    configure.args-delete   -DENABLE_XPDF_HEADERS=ON
    configure.args-append   -DENABLE_UTILS=OFF
    configure.args-append   -DENABLE_CPP=OFF
    configure.args-append   -DENABLE_GLIB=OFF

    post-destroot {
        file delete ${destroot}${prefix}/lib/pkgconfig/poppler-cairo.pc
    }
}

if {${subport} ne ${name}} {
    depends_extract-append  port:git

    depends_lib-append      port:poppler

    post-extract {
        system -W ${workpath} "${prefix}/bin/git clone --depth=1 http://anongit.freedesktop.org/git/poppler/test"
    }


# currently poppler only provides unit tests for the Qt wrappers

    test.run    yes
    test.dir    test
    test.target test

    post-destroot {
        foreach dot_h [glob -nocomplain -directory ${destroot}${prefix}/include/poppler *.h] {
            delete $dot_h
        }
        foreach libpoppler [glob -nocomplain ${destroot}${prefix}/lib/libpoppler.*] {
            delete ${libpoppler}
        }
        delete  ${destroot}${prefix}/include/poppler/fofi \
                ${destroot}${prefix}/include/poppler/goo \
                ${destroot}${prefix}/include/poppler/splash \
                ${destroot}${prefix}/lib/pkgconfig/poppler-splash.pc \
                ${destroot}${prefix}/lib/pkgconfig/poppler.pc
    }
} else {
    # generation of Poppler-0.18.gir fails if previous version of poppler is active
    # and new symbols are introduced, appropriate for main poppler port only
    conflicts_build ${name}
}

livecheck.type      regex
livecheck.url       ${homepage}releases.html
livecheck.regex     "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
